package com.example.websocket_chat.shiro;

import com.example.websocket_chat.model.User;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.stereotype.Component;

/**
 * @author jt
 * @version 1.0.0
 * @Description 类描述
 * @createTime 2021年11月17日 15:22:00
 */
@Component
public class MyRealm extends AuthorizingRealm {
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken)  authenticationToken;
        String username = usernamePasswordToken.getUsername();
        User user = new User(username,"123");
        if(user == null){
            return null;
        }
        return  new SimpleAuthenticationInfo(username,user.getPassword(),getName());
    }
}
